package com.xiaofengstu.mcams.web.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaofengstu.mcams.annotation.ILog;
import com.xiaofengstu.mcams.dto.BasicResultDTO;
import com.xiaofengstu.mcams.enums.RespStatusEnum;
import com.xiaofengstu.mcams.web.entity.TMenu;
import com.xiaofengstu.mcams.web.service.TMenuService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author fengzeng
 * @since 2022-05-07
 */
@RestController
@RequestMapping("/web/menu")
@RequiredArgsConstructor
public class TMenuController {

  private final TMenuService menuService;

  @ILog("获取用户权限")
  @GetMapping("/menus")
  public BasicResultDTO<List<TMenu>> getMenu() {
    return new BasicResultDTO<>(RespStatusEnum.SUCCESS, menuService.getMenuList());
  }

  @ILog("获取所有权限")
  @GetMapping("/list")
  public BasicResultDTO<List<TMenu>> getAllMenus() {
    return new BasicResultDTO<>(RespStatusEnum.SUCCESS, menuService.list(new QueryWrapper<>()));
  }

  @ILog("获取权限（树结构）")
  @GetMapping("/tree")
  public BasicResultDTO<List<TMenu>> getAllMenusTree() {
    return new BasicResultDTO<>(RespStatusEnum.SUCCESS, menuService.getAllMenusTree());
  }


  @ILog("删除权限")
  @GetMapping("/del")
  public BasicResultDTO<Integer> delByRoleId(@RequestParam("roleId") Integer roleId, @RequestParam("menuId") Integer menuId) {
    return new BasicResultDTO<>(RespStatusEnum.SUCCESS, menuService.removeByMenuId(roleId, menuId));
  }


  @ILog("通过角色ID查询权限")
  @GetMapping("/byRoleId")
  public BasicResultDTO<List<TMenu>> delByRoleId(@RequestParam("roleId") Integer roleId) {
    return new BasicResultDTO<>(RespStatusEnum.SUCCESS, menuService.getByRoleId(roleId));
  }






}
